import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import './assets/css/global.css'
import 'element-ui/lib/theme-chalk/index.css'
import './assets/icons'
import echarts from 'echarts'

import { MessageBox } from 'element-ui'

import iconPicker from 'e-icon-picker'

import 'e-icon-picker/dist/symbol.js' //基本彩色图标库
import 'e-icon-picker/dist/index.css' // 基本样式，包含基本图标
import 'font-awesome/css/font-awesome.min.css' //font-awesome 图标库
import 'element-ui/lib/theme-chalk/icon.css' //element-ui 图标库

Vue.use(ElementUI);
Vue.use(iconPicker,{
  FontAwesome: true,
  ElementUI: true,
  eIcon: true,
  eIconSymbol: true
})
Vue.use(echarts)

Vue.config.productionTip = false

Vue.prototype.handleTree = function handleTree (data, id, parentId, children, rootId) {
  id = id || 'id'
  parentId = parentId || 'parentId'
  children = children || 'children'
  rootId = rootId || Math.min.apply(Math, data.map(item => {
    return item[parentId]
  })) || 0
  //对源数据深度克隆
  const cloneData = JSON.parse(JSON.stringify(data))
  //循环所有项
  const treeData = cloneData.filter(father => {
    let branchArr = cloneData.filter(child => {
      //返回每一项的子级数组
      return father[id] === child[parentId]
    })
    branchArr.length > 0 ? father.children = branchArr : ''
    //返回第一层
    return father[parentId] === rootId
  })
  return treeData !== '' ? treeData : data
}

Vue.prototype.resetForm = function resetForm (formName) {
  if (this.$refs[formName] !== undefined) {
    this.$refs[formName].resetFields()
  }
}

Vue.prototype.msgSuccess = function (msg) {
  this.$message({
    showClose: true,
    message: msg,
    type: 'success'
  })
}

Vue.prototype.msgError = function (msg) {
  this.$message({
    showClose: true,
    message: msg,
    type: 'error'
  })
}

Vue.prototype.msgWarning = function (msg) {
  this.$message({
    showClose: true,
    message: msg,
    type: 'warning'
  })
}


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
